<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>BCC权限代理服务</title>
<script type="text/javascript" src="../static/js/jQuery-2.1.4.min.js"></script>
<script type="text/javascript" src="../static/js/jquery.serializeJSON.js"></script>
<script type="text/javascript">
$(function() {
	$("#testQueryMenuByUser").click(function(){
		$.ajax({
			url : "auth/menu/list?t="+(new Date()).valueOf(),
			method : "GET",
			data: {"appId":"tesla-authproxy"},
			dataType : "json",
			async : false,
			success : function(data) {
				if(data.code == "401"){
					alert("401，没有登录，跳转到登录页面");
					window.location.href=data.message;
				}else{
					var ret = JSON.stringify(data.data);
					$("#result").html("");
					$("#result").html("code:"+data.code+"data:"+ret+",message:"+data.message);
				}
			},
			error : function(XMLHttpRequest, textStatus, errorThrown) {
			}
		});
	});

	$("#testQueryMenuByApp").click(function(){
		$.ajax({
			url : "auth/menu/all?t="+(new Date()).valueOf(),
			method : "GET",
			data: {"appId":"tesla-authproxy"},
			dataType : "json",
			async : false,
			success : function(data) {
				if(data.code == "401"){
					alert("401，没有登录，跳转到登录页面");
					window.location.href=data.message;
				}else{
					var ret = JSON.stringify(data.data);
					$("#result").html("");
					$("#result").html("code:"+data.code+"data:"+ret+",message:"+data.message);
				}
			},
			error : function(XMLHttpRequest, textStatus, errorThrown) {
			}
		});
	});

	$("#testQueryOwnerRoles").click(function(){
		$.ajax({
			url : "auth/role/all?t="+(new Date()).valueOf(),
			method : "GET",
			data: {"appId":"tesla-authproxy"},
			dataType : "json",
			async : false,
			success : function(data) {
				if(data.code == "401"){
					alert("401，没有登录，跳转到登录页面");
					window.location.href=data.message;
				}else{
					var ret = JSON.stringify(data.data);
					$("#result").html("");
					$("#result").html("code:"+data.code+"data:"+ret+",message:"+data.message);
				}
			},
			error : function(XMLHttpRequest, textStatus, errorThrown) {
			}
		});
	});

	
	$("#testCheck").click(function(){
		$.ajax({
			url : "permission/check?t="+(new Date()).valueOf(),
			method : "GET",
			data: {"appId":"tesla-authproxy","permissionName":"ais:tesla:ads:op:del"},
			dataType : "json",
			async : false,
			success : function(data) {
				if(data.code == "401"){
					alert("401，没有登录，跳转到登录页面");
					window.location.href=data.message;
				}else{
					var ret = JSON.stringify(data.data);
					$("#result").html("");
					$("#result").html("code:"+data.code+"data:"+ret+",message:"+data.message);
				}
			},
			error : function(XMLHttpRequest, textStatus, errorThrown) {
			}
		});
	});
	//测试-查询用户所有权限
	$("#testQueryAllPermission").click(function(){
		$.ajax({
			url : "permission/list?t="+(new Date()).valueOf(),
			method : "GET",
			data: {"appId":"tesla-authproxy"},
			dataType : "json",
			async : false,
			success : function(data) {
				if(data.code == "401"){
					alert("401，没有登录，跳转到登录页面");
					window.location.href=data.message;
				}else{
					var ret = JSON.stringify(data.data);
					$("#result").html("");
					$("#result").html("code:"+data.code+"data:"+ret+",message:"+data.message);
				}
			},
			error : function(XMLHttpRequest, textStatus, errorThrown) {
			}
		});
	});
	
	//测试-批量添加角色
	$("#batchAddRole").click(function(){
		var roles = [{"roleCode":"odps_admin",roleName:"odps管理员","memo":"odps运维管理员"},{"roleCode":"ads_admin",roleName:"ads管理员","memo":"ads运维管理员"},];
		$.ajax({
			url : "auth/role/batchAdd?t="+(new Date()).valueOf(),
			method : "POST",
			contentType:"application/json",
			data: JSON.stringify(roles),
			dataType : "json",
			async : false,
			success : function(data) {
				if(data.code == "401"){
					alert("401，没有登录，跳转到登录页面");
					window.location.href=data.message;
				}else{
					var ret = JSON.stringify(data.data);
					$("#result").html("");
					$("#result").html("code:"+data.code+"data:"+ret+",message:"+data.message);
				}
			},
			error : function(XMLHttpRequest, textStatus, errorThrown) {
			}
		});
	});

	//initMenu
	$("#initMenu").click(function(){
		var initData = {appId:"tesla-authproxy",menus:[{ name:"运维中心", sref:"", comment:"运维服务", children:[ {name:"升级",sref:"bccweb.operationcenter.update",comment:"升级服务"}, {name:"重启",sref:"bccweb.operationcenter.restart",comment:"重启热加载功能"} ] },{ name:"后台管理",   sref:"", comment:"运维服务", children:[] }]};
		$.ajax({
			url : "auth/menu/init?t="+(new Date()).valueOf(),
			method : "POST",
			contentType:"application/json",
			data: JSON.stringify(initData),
			dataType : "json",
			async : false,
			success : function(data) {
				if(data.code == "401"){
					alert("401，没有登录，跳转到登录页面");
					window.location.href=data.message;
				}else{
					var ret = JSON.stringify(data.data);
					$("#result").html("");
					$("#result").html("code:"+data.code+"data:"+ret+",message:"+data.message);
				}
			},
			error : function(XMLHttpRequest, textStatus, errorThrown) {
			}
		});
	});

	//initMenuNew
	$("#initMenuNew").click(function(){
		var initData = {appId:"tesla-authproxy",menus:[{ name:"运维中心", icon:"test", sref:"", comment:"运维服务", children:[ {name:"升级",icon:"test",sref:"bccweb.operationcenter.update",comment:"升级服务"}, {name:"重启",icon:"test",sref:"bccweb.operationcenter.restart",comment:"重启热加载功能"} ] },{ name:"后台管理", icon:"test",  sref:"", comment:"运维服务", children:[] }]};
		$.ajax({
			url : "auth/menu/init?t="+(new Date()).valueOf(),
			method : "POST",
			contentType:"application/json",
			data: JSON.stringify(initData),
			dataType : "json",
			async : false,
			success : function(data) {
				if(data.code == "401"){
					alert("401，没有登录，跳转到登录页面");
					window.location.href=data.message;
				}else{
					var ret = JSON.stringify(data.data);
					$("#result").html("");
					$("#result").html("code:"+data.code+"data:"+ret+",message:"+data.message);
				}
			},
			error : function(XMLHttpRequest, textStatus, errorThrown) {
			}
		});
	});

	//getDataPermission
	$("#getDataPermission").click(function(){
		$.ajax({
			url : "permission/data?appId=tesla-authproxy&permissionName=db_data&t="+(new Date()).valueOf(),
			method : "GET",
			contentType:"application/json",
			dataType : "json",
			async : false,
			success : function(data){
				if(data.code == "401"){
					alert("401，没有登录，跳转到登录页面");
					window.location.href=data.message;
				}else{
					var ret = JSON.stringify(data.data);
					$("#result").html("");
					$("#result").html("code:"+data.code+"data:"+ret+",message:"+data.message);
				}
			},
			error : function(XMLHttpRequest, textStatus, errorThrown) {
			}
		});
	});
});
</script>
</head>
<body>
	<h2>欢迎使用BCC权限代理服务</h2>
	<ul>
		<h3>系统介绍</h3>
		<li>实现了不同的账户登录和权限控制逻辑切换，对上层业务屏蔽了内部和专有云不同环境下的账户登录和权限控制的差异化，让上层业务能快速接入并满足各个环境的权限安全体系要求。</li>
		<li>BCC权限代理服务内部对接BUC+ACL，专有云对接AAS+OAM。</li>
	</ul>
	
	<ul>
		<h3>菜单接口测试</h3>

		<li><a href="#" id="initMenu">菜单初始化</a></li>

		<li><a href="#" id="initMenuNew">菜单初始化并授权给默认角色</a></li>

		<li><a href="#" id="testQueryMenuByUser">test查询当前登录用户的菜单权限数据</a></li>

		<li><a href="#" id="testQueryMenuByApp">test查询应用下的所有菜单</a></li>
	</ul>
	<ul>
		<h3>角色接口测试</h3>
		<li><a href="#" id="testQueryOwnerRoles">查询当前登录用户管理角色列表</a></li>

		<li><a href="#" id="batchAddRole">批量添加角色</a></li>

	</ul>

	<ul>
		<h3>权限接口测试</h3>

		<li><a href="#" id="testCheck">验证ADS删除DB权限[ais:bcc:ads:op:del]</a></li>

		<li><a href="#" id="addPermission">添加权限</a></li>

		<li><a href="#" id="getDataPermission">获取当前登录用户的数据权限（指定数据权限名称为db_data）</a></li>

	</ul>

	<ul>
		<h3>注销接口测试</h3>
		<li><a href="auth/logout?appId=tesla-authproxy">注销</a></li>
	</ul>
	
	<ul>
		<h3>运行结果</h3>
		<p id="result"></p>
	</ul>

</body>
</html>